package com.demo.xmtx.controller;

import com.demo.xmtx.entity.GisObject;
import com.demo.xmtx.service.GisObjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/gis")
@Tag(name = "gis管理")
public class GisObjectController {

    @Autowired
    private GisObjectService gisObjectService;

    @Operation(summary = "保存gis数据")
    @PostMapping
    public boolean save(@RequestBody GisObject gisObject) {
        return gisObjectService.save(gisObject);
    }

    @Operation(summary = "根据id查询gis数据")
    @Parameters({
            @Parameter(name = "id",description = "文件id",in = ParameterIn.PATH),
            @Parameter(name = "token",description = "请求token",required = true,in = ParameterIn.HEADER),
            @Parameter(name = "name",description = "文件名称",required = true,in=ParameterIn.QUERY)
    })
    @GetMapping("/{id}")
    public GisObject getById(@PathVariable("id") String id,@RequestHeader("token") String token, @RequestParam("name")String name,@RequestBody GisObject gisObject) {
        return gisObjectService.getById(id);
    }

    @PutMapping("/{id}")
    public boolean updateById(@PathVariable Long id, @RequestBody GisObject gisObject) {
//        gisObject.setId(id);
        return gisObjectService.updateById(gisObject);
    }

    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return gisObjectService.removeById(id);
    }

    @GetMapping
    public List<GisObject> list() {
        return gisObjectService.list();
    }
}
